]> git.neil.brown.name Git - wiggle.git/commitdiff
Split non-static code out of wiggle.c
authorNeilBrown <neil@brown.name>
Sat, 3 Oct 2020 10:05:57 +0000 (20:05 +1000)
committerNeilBrown <neil@brown.name>
Sat, 3 Oct 2020 10:05:57 +0000 (20:05 +1000)
wiggle.c container some code that other files reference.
Now that this other file can live in a library (libwiggle),
move that code into a new file - util.c - so it is
available in the library.

Signed-off-by: NeilBrown <neil@brown.name>
Makefile
utils.c [new file with mode: 0644]
wiggle.c

index 231106740eab07fba2f0866c271bdc0242dba377..69427750423c62ee674bd50681a3eb99b894c6a6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ O=O
 BIN=.
 DOC=.
 
-LIBOBJ= load.o parse.o split.o extract.o diff.o bestmatch.o merge2.o ccan/hash/hash.o
+LIBOBJ= load.o parse.o split.o extract.o diff.o bestmatch.o merge2.o utils.o ccan/hash/hash.o
 OBJ=wiggle.o ReadMe.o vpatch.o
 
 BOBJ=$(patsubst %.o,$(O)/%.o,$(OBJ))
diff --git a/utils.c b/utils.c
new file mode 100644 (file)
index 0000000..37e9a32
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,76 @@
+/*
+ * wiggle - apply rejected patches
+ *
+ * Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (C) 2010-2013 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2014-2020 Neil Brown <neil@brown.name>
+ *
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program.
+ *
+ *    Author: Neil Brown
+ *    Email: <neil@brown.name>
+ */
+
+#include       "wiggle.h"
+#include       <unistd.h>
+#include       <stdlib.h>
+#include       <sys/stat.h>
+
+char *Cmd = "wiggle";
+
+int do_trace = 0;
+
+void *xmalloc(int size)
+{
+       void *rv = malloc(size);
+       if (size && !rv) {
+               char *msg = "Failed to allocate memory - aborting\n";
+               write(2, msg, strlen(msg));
+               exit(3);
+       }
+       return rv;
+}
+
+void printword(FILE *f, struct elmnt e)
+{
+       if (e.start[0])
+               fprintf(f, "%.*s", e.plen + e.prefix,
+                       e.start - e.prefix);
+       else {
+               int a, b, c;
+               sscanf(e.start+1, "%d %d %d", &a, &b, &c);
+               fprintf(f, "*** %d,%d **** %d%s", b, c, a, e.start+18);
+       }
+}
+
+void die(char *reason)
+{
+       fprintf(stderr, "%s: fatal error: %s failure\n", Cmd, reason);
+       exit(3);
+}
+
+void check_dir(char *name, int fd)
+{
+       struct stat st;
+       if (fstat(fd, &st) != 0) {
+               fprintf(stderr, "%s: fatal: %s is strange\n", Cmd, name);
+               exit(3);
+       }
+       if (S_ISDIR(st.st_mode)) {
+               fprintf(stderr, "%s: %s is a directory\n", Cmd, name);
+               exit(3);
+       }
+}
+
index efdd39649da2367a2a47b85caceb42ea1431393e..e7444a80051f1ba063766054189a2a4cf0999b37 100644 (file)
--- a/wiggle.c
+++ b/wiggle.c
 #include       <ctype.h>
 #include       <sys/stat.h>
 
-char *Cmd = "wiggle";
-int do_trace = 0;
-
-void die(char *reason)
-{
-       fprintf(stderr, "%s: fatal error: %s failure\n", Cmd, reason);
-       exit(3);
-}
-
-void check_dir(char *name, int fd)
-{
-       struct stat st;
-       if (fstat(fd, &st) != 0) {
-               fprintf(stderr, "%s: fatal: %s is strange\n", Cmd, name);
-               exit(3);
-       }
-       if (S_ISDIR(st.st_mode)) {
-               fprintf(stderr, "%s: %s is a directory\n", Cmd, name);
-               exit(3);
-       }
-}
-
-void *xmalloc(int size)
-{
-       void *rv = malloc(size);
-       if (size && !rv) {
-               char *msg = "Failed to allocate memory - aborting\n";
-               write(2, msg, strlen(msg));
-               exit(3);
-       }
-       return rv;
-}
-
-void printword(FILE *f, struct elmnt e)
-{
-       if (e.start[0])
-               fprintf(f, "%.*s", e.plen + e.prefix,
-                       e.start - e.prefix);
-       else {
-               int a, b, c;
-               sscanf(e.start+1, "%d %d %d", &a, &b, &c);
-               fprintf(f, "*** %d,%d **** %d%s", b, c, a, e.start+18);
-       }
-}
-
 static void printsep(struct elmnt e1, struct elmnt e2)
 {
        int a, b, c, d, e, f;